package com.example.planetandzombiedemo.entity;

import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.Base64;

import com.example.planetandzombiedemo.global.Config;
import com.example.planetandzombiedemo.model.BaseModel;
import com.example.planetandzombiedemo.view.GameView;

public class Bullet extends BaseModel {
    //子弹产生时间
    private long birthTime = 0l;
    //x轴上的分量
    private float speedx = 10;

    public Bullet(int locationX, int locationY) {
        this.locationX = locationX;
        this.locationY = locationY;
        this.isAlife = true;
        birthTime = System.currentTimeMillis();
    }

    @Override
    public void drawSelf(Canvas canvas, Paint paint) {
        if (isAlife) {
            //子弹移动：从左往右
            locationX += speedx;
            //边界处理，游戏画面外消失
            if (locationX > Config.deviceWidth) {
                isAlife = false;
            }
            canvas.drawBitmap(Config.bullet, locationX, locationY, paint);
        }
    }

    @Override
    public int getModelWidth() {
        return Config.bullet.getWidth();
    }
}
